package com.lanxin.oa.zc.dao.daoImpl;

import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.ZcAsset;
import com.lanxin.oa.zc.dao.ZcAssetDao;
import org.springframework.stereotype.Repository;

import java.util.Calendar;
import java.util.List;

@Repository
public class ZcAssetDaoImpl extends BaseDaoImpl implements ZcAssetDao {

    @Override
    public List selectzcAsset() {
        return super.queryAll("select distinct zcset  from ZcAsset zcset left join fetch zcset.zctype left join fetch zcset.jcly left join fetch zcset.jcdd left join fetch zcset.empjb left join fetch zcset.empcj left join fetch zcset.empkg");
    }

    @Override
    public List selectzcTypeIdandName() {
        return super.queryAll("from ZcAssettype zctype where zctype.status!='0'");
    }

    @Override
    public ZcAsset selectzcAssetById(Integer oid) {
        return (ZcAsset) super.getById(ZcAsset.class,oid);
    }

    @Override
    public List selectJcbaseByIdandName() {
        return super.queryAll("from JcBasicdatavalue where state = '1' and type = 5");
    }

    @Override
    public List selectJcbaseByDd() {
        return super.queryAll(" from JcBasicdatavalue jc where jc.state = '1' and jc.type = 3");    }

    @Override
    public List selectEmpByIdandName() {
        return super.queryAll("from ZzEmployee");
    }

    @Override
    public Integer getZcInfoCount() {
        Calendar car = Calendar.getInstance();

        String currentDate =String.valueOf(car.get(Calendar.YEAR))+"-"+String.valueOf(car.get(Calendar.MONTH)+1)+"-"+String.valueOf(car.get(Calendar.DATE));
        System.out.println(currentDate);
        String hql = "select count(*) from ZcAsset  where date_format(createDate,'%Y-%m-%d') = str_to_date('"+currentDate+"','%Y-%m-%d')";

        Integer row = Integer.valueOf(selectByHQL(hql).toString());
        return row;
    }

    @Override
    public List selecttiaojian(Integer type, String assetCode, String assetNanme) {
        String hql="select distinct zcset  from ZcAsset zcset left join fetch zcset.zctype left join fetch zcset.jcly left join fetch zcset.jcdd left join fetch zcset.empjb left join fetch zcset.empcj left join fetch zcset.empkg where 1=1 ";

        if (type != null && !type.equals("")) {
            hql = hql + "  and zcset.type = '" + type + "'  ";
        }
        if (assetCode != null && !assetCode.equals("")) {
            hql = hql + " and zcset.assetCode = '" + assetCode + "'  ";
        }
        if (assetNanme != null && !assetNanme.equals("")) {

            hql = hql + " and zcset.assetNanme = '" + assetNanme + "' ";
        }
        return queryAll(hql);
    }


}
